Button (PIXI) Class
A Multipurpose button class. It is designed to have one image, and an optional text label. The button can be a normal button or a selectable button. The button functions similarly with both CreateJS and PIXI, but slightly differently in initialization and callbacks. Use releaseCallback and overCallback to know about button clicks and mouse overs, respectively.
Constructor
Button (PIXI)
-
[imageSettings]
-
[label=null]
-
[enabled=true]
Parameters:
-
[imageSettings]
Object optionalInformation about the art to be used for button states, as well as if the button is selectable or not.
-
[priority=null]
Array optionalThe state priority order. If omitted, defaults to ["disabled", "down", "over", "up"]. Previous versions of Button used a hard coded order: ["highlighted", "disabled", "down", "over", "selected", "up"].
-
[up]
Object | PIXI.Texture optionalThe texture for the up state of the button. This can be either the texture itself, or an object with 'tex' and 'label' properties.
-
[tex]
PIXI.Texture optionalThe sourceRect for the state within the image. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
-
-
[over=null]
Object | PIXI.Texture optionalThe texture for the over state of the button. If omitted, uses the up state.
-
[tex]
PIXI.Texture optionalThe sourceRect for the state within the image. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
-
-
[down=null]
Object | PIXI.Texture optionalThe texture for the down state of the button. If omitted, uses the up state.
-
[tex]
PIXI.Texture optionalThe sourceRect for the state within the image. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
-
-
[disabled=null]
Object | PIXI.Texture optionalThe texture for the disabled state of the button. If omitted, uses the up state.
-
[tex]
PIXI.Texture optionalThe sourceRect for the state within the image. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" and "type" from the label parameter may be overridden.
-
-
[<yourCustomState>=null]
Object | PIXI.Texture optionalThe visual information about a custom state found in imageSettings.priority. Any state added this way has a property of the same name added to the button. Examples of previous states that have been moved to this system are "selected" and "highlighted".
-
[tex]
PIXI.Texture optionalThe texture for the custom state. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
-
-
[origin=null]
PIXI.Point optionalAn optional offset for all button graphics, in case you want button positioning to not include a highlight glow, or any other reason you would want to offset the button art and label.
-
[scale=1]
Number optionalThe scale to use for the textures. This allows smaller art assets than the designed size to be used.
-
-
[label=null]
Object optionalInformation about the text label on the button. Omitting this makes the button not use a label.
-
[type]
String optionalIf label.type is "bitmap", then a PIXI.BitmapText text is created, otherwise a PIXI.Text is created for the label.
-
[text]
String optionalThe text to display on the label.
-
[style]
Object optionalThe style of the text field, in the format that PIXI.BitmapText and PIXI.Text expect.
-
[x="center"]
String | Number optionalAn x position to place the label text at relative to the button.
-
[y="center"]
String | Number optionalA y position to place the label text at relative to the button. If omitted, "center" is used, which attempts to vertically center the label on the button.
-
-
[enabled=true]
Boolean optionalWhether or not the button is initially enabled.
Item Index
Methods
_addProperty
-
propertyName
Adds a property to the button. Setting the property sets the value in _stateFlags and calls _updateState().
Parameters:
-
propertyName
StringThe property name to add to the button.
_onDown
()
private
The callback for when the button receives a mouse down event.
_onOut
()
private
The callback for when the mouse leaves the button area.
_onOver
()
private
The callback for when the button is moused over.
_onUp
()
private
The callback for when the button for when the mouse/touch is released on the button
- only when the button was held down initially.
_onUpOutside
()
private
The callback for when the mouse/touch is released outside the button when the button was held down.
initialize
-
[imageSettings]
-
[label=null]
-
[enabled=true]
Constructor for the button when using PIXI.
Parameters:
-
[imageSettings]
Object optionalInformation about the art to be used for button states, as well as if the button is selectable or not.
-
[label=null]
Object optionalInformation about the text label on the button. Omitting this makes the button not use a label.
-
[enabled=true]
Boolean optionalWhether or not the button is initially enabled.
Properties
_currentLabelStyle
Object
private
The current style for the label, to avoid setting this if it is unchanged.
_offset
PIXI.Point
private
An offset to button positioning, generally used to adjust for a highlight around the button.
_stateData
Object
private
A dictionary of state graphic data, keyed by state name. Each object contains the sourceRect (src) and optionally 'trim', another Rectangle. Additionally, each object will contain a 'label' object if the button has a text label.
_statePriority
Array
private
An array of state names (Strings), in their order of priority. The standard order previously was ["highlighted", "disabled", "down", "over", "selected", "up"].